package com.ztstkj.lzboard.adapters

import android.graphics.Color
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.ztstkj.lzboard.R
import com.ztstkj.lzservices.dto.boards.BoardRankOutput

class UserRankAdapter(private var datas: List<BoardRankOutput>) :
    RecyclerView.Adapter<UserRankAdapter.ItemViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {
        val v = LayoutInflater.from(parent.context)
            .inflate(R.layout.rank_item, parent, false)
        return ItemViewHolder(v)
    }

    override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {
        try {
            val bean = datas[position]
            if (position % 2 == 1) {
                holder.itemView.setBackgroundResource(R.drawable.table_bg_odd) // 偶数行颜色
            }
            if (bean.number < 4) {
                holder.rankNumber.setTextColor(Color.WHITE)
                holder.rankNumber.setBackgroundResource(R.drawable.table_bg_top_tag)
            }
            holder.rankNumber.text = bean.number.toString()
            holder.rankRoom.text = bean.home.toString()
            holder.rankPoint.text = bean.point.toString()
        } catch (e: Exception) {
            e.printStackTrace()
        }

    }

    override fun getItemCount(): Int {
        return datas.size
    }

    inner class ItemViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val rankNumber: TextView = view.findViewById(R.id.tvRankNumber)
        val rankRoom: TextView = view.findViewById(R.id.tvRankRoom)
        val rankPoint: TextView = view.findViewById(R.id.tvRankPoint)
    }
}